<?PHP

 require_once('/home/dmdirc/www/addons/inc/private.database.php');

 $status = false !== @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
 $status = $status & @mysql_select_db(DB_NAME);

 if ($status) {
  $sql = 'SELECT version_id, addon_id, version_fileversion, version_version, version_stable, version_unstable FROM versions NATURAL JOIN addons WHERE addon_verified = \'yes\'';
  $res = mysql_query($sql);

  while ($row = mysql_fetch_assoc($res)) {
   $channels = array();

   if ((int) $row['version_stable'] == 1) {
    $channels[] = 'STABLE';
   }

   if ((int) $row['version_unstable'] == 1) {
    $channels[] = 'UNSTABLE';
    $channels[] = 'NIGHTLY';
    $channels[] = 'NONE';
   }

   foreach ($channels as $channel) {
    $_VERSIONS['addon-' . $row['addon_id']][$channel] = array(
 	'id' => (int) $row['version_fileversion'],
 	'string' => $row['version_version'],
 	'file' => 'http://addons.dmdirc.com/addondownload/' . $row['version_id']
    );
   }
  }
 }

?>
